package com.itholmes.usercenter.common;

/**
 * @projectName: user-center
 * @package: com.itholmes.usercenter.common
 * @className: ResultUtils
 * @author: xuyanbo
 * @description: 返回工具类
 * @date: 2022/7/25 20:52
 */
public class ResultUtils {

    /**
     * 通用返回 成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> BaseResponse<T> success(T data){
        return new BaseResponse<>(0,data,"ok");
    }

    /**
     * 通用返回 失败
     * @param errorCode
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode){
        return new BaseResponse(errorCode);
    }

    /**
     * 失败
     * @param code
     * @param messsage
     * @param description
     * @return
     */
    public static BaseResponse error(int code,String messsage,String description){
        return new BaseResponse(code,null,messsage,description);
    }
    /**
     * 失败
     * @param errorCode
     * @param messsage
     * @param description
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode,String messsage,String description){
        return new BaseResponse(errorCode.getCode(),null,messsage,description);
    }

    /**
     *  失败
     * @param errorCode
     * @param description
     * @return
     */
    public static BaseResponse error(ErrorCode errorCode,String description){
        return new BaseResponse(errorCode.getCode(),errorCode.getMessage(),description);
    }

}
